﻿
module Sustainalytics.Portfolio {

    import Common = Sustainalytics.Common;
    import SearchBox = Sustainalytics.SearchBox;
    export interface IPortfolioSharedSearchBoxService {
        // Search for items given a term and paging options
        Search(searchData: any, skip: number, take: number): ng.IHttpPromise<any[]>;
    }
    export class PortfolioSharedSearchBoxServiceAdapter implements IPortfolioSharedSearchBoxService {

        private portfolioSearchService: PortfolioSearchService;

        public constructor(portfolioSearchService: PortfolioSearchService) {
            this.portfolioSearchService = portfolioSearchService;
        }

        public Search(searchData: any, skip: number, take: number): ng.IHttpPromise<any[]> {

            var lstPromise: ng.IHttpPromise<PortfolioDto[]> = this.portfolioSearchService.SearchScreeningToolPortfolio(searchData, skip, take);
            return lstPromise;
        }
    }

    var portfolioSearchModule = angular.module('Sustainalytics.Portfolio');

    portfolioSearchModule.factory('PortfolioSharedSearchBoxServiceAdapter', ($http: ng.IHttpService, $rootScope: ng.IScope) => {

        var portfolioSearchService = new Sustainalytics.Portfolio.PortfolioSearchService($http, $rootScope);

        var adapter = new Sustainalytics.Portfolio.PortfolioSharedSearchBoxServiceAdapter(portfolioSearchService);

        return adapter;
    });
}